package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Dictionary;
import cn.wolfcode.crm.mapper.DictionaryMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDictionaryService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: crm
 * @description:
 * @author: Mr.chen
 * @create: 2018-07-07 21:45
 **/
@Service
public class DictionaryServiceImpl implements IDictionaryService {
    @Autowired
    private DictionaryMapper mapper;

    public void save(Dictionary entity) {
        mapper.insert(entity);
    }

    public void update(Dictionary entity) {
        mapper.updateByPrimaryKey(entity);
    }

    public void delete(long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public Dictionary get(long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<Dictionary> list() {
        return mapper.selectAll();
    }

    @Override
    public PageResult query(QueryObject qo) {
        int total = mapper.queryForCount(qo);
        if (total == 0) {
            return new PageResult();
        }
        List<Dictionary> list = mapper.queryForList(qo);
        return new PageResult(total, list);
    }

}
